<?php
		
		require_once('db_connect.php');

		$id=$_POST['id'];
		$passwd=$_POST['passwd'];
		$passwd_confirm=$_POST['passwd_confirm'];
		$name=$_POST['name'];
		$email=$_POST['email'];
		$gender=$_POST['gender'];
		$edulevel=$_POST['edulevel'];
		$addr=$_POST['addr'];
		$age=$_POST['age'];
		$phone1=$_POST['phone1'];
		$phone2=$_POST['phone2'];
		$phone3=$_POST['phone3'];
		$birth1=$_POST['birth1'];
		$birth2=$_POST['birth2'];
		$birth3=$_POST['birth3'];
		$category=$_POST['category'];
		$keyword=$_POST['keyword'];	

		$category1 = $_POST['category1'];
		$category2 = $_POST['category2'];
		$category3 = $_POST['category3'];
		$category4 = $_POST['category4'];
		$category5 = $_POST['category5'];
		$category6 = $_POST['category6'];
		$category7 = $_POST['category7'];
		$category8 = $_POST['category8'];
		$category9 = $_POST['category9'];
		$category10 = $_POST['category10'];			

		$sql="select * from member where id='$id'";
		$result=mysqli_query($conn, $sql);
		$exist_id=mysqli_num_rows($result);
		
		if($exist_id)
		{
			echo("<script>
					window.alert('해당 아이디가 존재합니다')
					history.go(-1)
					</script>");
			exit;
		}		
		$ip=$_SERVER['REMOTE_ADDR'];
		$phone=$phone1."-".$phone2."-".$phone3;
		$birth=$birth1."-".$birth2."-".$birth3;
				
		$sql="insert into member(id,passwd,name,gender,age,edulevel,phone,birth,email,addr)";
		$sql.="values('$id','$passwd','$name','$gender','$age','$edulevel','$phone','$birth','$email','$addr')";
				
		mysqli_query($conn,$sql);
		
		$tok = strtok($keyword, ",");
		while($tok!='')
		{
			$sql="INSERT INTO keyword_mem (`mem_id`, `keyword`) VALUES ('$id','$tok');";
			mysqli_query($conn, $sql);
			$tok = strtok(",");
		}
		
		for($i=1; $i<11; $i++)
		{
			if(${"category".$i})
			{	
				$temp = ${"category".$i};			
				$sql="insert into category_mem(mem_id, category)values('$id','$temp')";
				mysqli_query($conn, $sql);				
			}
		}		
		
		mysqli_close($conn);
		
		//이동
		Header("Location:main.php");
	
?>
		